<template>
	<!-- 邀请款记录 -->
	<view class="paymengt_recordBox">
		<view>
			<view class="record_title">
				<image src="https://api.luyiwangluo.com/upload/uniapp/user/Invitation-code-recording.png" mode=""></image>
				<text>收款：{{ total_money }}元</text>
			</view>
			<view class="record_date">
				<view class="date_start">
					<text>开始时间</text>
					<picker mode="date" :value="dateStart" :start="startValidDate" @change="getDateStart">
						<view>{{ dateStart }}</view>
					</picker>
				</view>
				<view class="date_end">
					<text>结束时间</text>
					<picker mode="date" :value="dateEnd" :start="endValidDate" @change="getDateEnd">
						<view>{{ dateEnd }}</view>
					</picker>
				</view>
				<view class="date_btn" @tap="getNewDate(2)">查询</view>
			</view>
		</view>
		<!-- 收益列表区域 -->
		<view>
			<block v-for="(item, index) in dataList" :key="item.id">
				<view class="record_list">
					<view class="list_left">
						<view class="record_phone">{{ item.name }}</view>
						<view class="record_time">{{ item.created_at }}</view>
					</view>
					<view class="list_right">￥{{ item.money }}</view>
				</view>
			</block>
		</view>
		
	</view>
</template>
<script>
import code from '@/api/api.js';
import url from '@/api/url.js';
export default {
	data() {
		return {
			dateStart: '0', //开始的时间
			startime: 0,
			scrollTop:1,
			startValidDate: '2019-08-01', //开始有效时间的开始
			endValidDate: '2019-08-01', //结束时间的开始
			dateEnd: '0', //结束的时间
			endtime: 0,
			dataList: [],
			total_money: 0,
			total:1,
			pageIndex:1,
			pullUpOn: true,
		};
	},
	onLoad() {
		this.getNewDate(1);
	},
	onReachBottom: function() {
		if (!this.pullUpOn) return;
		this.loadding = true;
		if (this.pageIndex == this.total) {
			this.loadding = false;
			this.pullUpOn = false;
		} else {
			this.pageIndex = this.pageIndex + 1;
			this.getDataList();
		}
	},
	onPullDownRefresh() {
		this.init();
		this.getDataList();
		setTimeout(()=>{
			uni.stopPullDownRefresh();
		},1000)
	},
	methods: {
		getDateStart(e) {
			this.dateStart = e.detail.value; //开始时间
			this.endValidDate = this.dateStart;
		},
		getDateEnd(e) {
			this.dateEnd = e.detail.value; //结束时间
		},
		init(){
			this.dataList=[];
			this.pageIndex=1;
			this.total=1;
		},
		async getDataList() {
			let sefl=this;
			sefl.$londing();
			const res = await code(url.myCollection, {
				data: {
					start_time: sefl.startime,
					end_time: sefl.endtime,
					page: sefl.pageIndex
				}
			});
			if (res.data.code == 1) {
			sefl.total_money = res.data.data.total_money;
			sefl.dataList = sefl.dataList.concat(res.data.data.list);
			sefl.total=res.data.data.page;
			} else {
				sefl.$msg(res.data.msg);
			}
		},
		getNewDate(num) {
			//获取当前时间
			if (num == 1) {
				const newDate = new Date();
				let year = newDate.getFullYear();
				let month = newDate.getMonth() + 1;
				let day = newDate.getDate();
				// this.dateStart = `${year}-${month}-${day}`;
				this.dateStart = '请选择开始时间';
				const lastDate = new Date(year, month, 0); //获取这个月最后一天的日期
				let lastDay = lastDate.getDate(); //获取这个月最后一天的日期
				// this.dateEnd = `${year}-${month}-${lastDay}`;
				this.dateEnd = '请选择结束时间';
				this.startime =''
				this.endtime = ''
				this.init();
				this.getDataList();
			} else {
				if (this.dateStart == '0' || this.dateEnd == '0') {
					this.$msg('请选择查询时间');
				} else {
					
					this.startime = this.dateStart;
					this.endtime = this.dateEnd;
					this.init();
					this.getDataList();
				}
			}
		}
	},
	onPageScroll(e) {
		this.scrollTop = e.scrollTop;
	}
};
</script>

<style lang="scss">
.paymengt_recordBox {
	color: #333;
	// 提示头部区域
	.record_title {
		background-color: #536de6;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 32rpx;
		color: #ffffff;
		image {
			width: 36rpx;
			height: 36rpx;
			margin-right: 20rpx;
		}
	}
	.none {
		margin-top: 180rpx;
		text-align: center;
		> image {
			width: 280rpx;
			height: 260rpx;
		}
	}
	// 时间选择区域
	.record_date {
		padding: 0 30rpx;
		height: 128rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #8a9fff;
		color: #ffffff;
		> view {
			&:nth-child(-n + 2) {
				font-size: 26rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
			}
		}
		.date_end {
			border-left: 2rpx solid;
			padding-left: 84rpx;
		}
		.date_btn {
			width: 120rpx;
			height: 60rpx;
			background-color: #ffdf47;
			border-radius: 60rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #536de6;
			font-size: 30rpx;
			font-weight: 700;
		}
	}

	// 列表区域
	.record_list {
		padding: 20rpx;
		margin-bottom: 2rpx;
		display: flex;
		justify-content: space-between;
		background-color: #e6eaff;
		.list_left {
			.record_phone {
				font-size: 30rpx;
				font-weight: 700;
				margin-bottom: 10rpx;
			}
			.record_time {
				font-size: 26rpx;
				color: #999999;
			}
		}
		.list_right {
			font-size: 34rpx;
			font-weight: 700;
			display: flex;
			align-items: center;
		}
	}
}
</style>
